package com.kazalan.content.persistence;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.kazalan.domain.document.Section;

public class HibernateSectionDaoImpl extends HibernateDaoSupport implements SectionDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Section> getSectionByParentId(String parentId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Section.class);
		criteria.add(Restrictions.eq("parent_id", parentId));
		criteria.addOrder(Order.asc("order"));
		return getHibernateTemplate().findByCriteria(criteria);
	}

	@Override
	public Section getSectionById(String sectionId) {
		return getHibernateTemplate().get(Section.class, sectionId);
	}

	@Override
	public void saveSection(Section section) {
		getHibernateTemplate().saveOrUpdate(section);
	}

}
